package com.cwx.mychat.entity.enums;

import com.cwx.mychat.utils.stringUtils.StringUtil;

public enum JoinTypeEnum {

    JOIN(0, "直接加入"),
    APPLY(1, "需要审核");

    private Integer type;
    private String desc;

    JoinTypeEnum(Integer type, String desc){
        this.type = type;
        this.desc = desc;
    }

    public Integer getType() {
        return type;
    }
    public String getDesc(){
        return desc;
    }

    public static JoinTypeEnum getByName(String name){
        try {
            if(!StringUtil.isEmpty(name)){
                return JoinTypeEnum.valueOf(name.toUpperCase());
            }
            return null;
        }catch (IllegalArgumentException e){
            return null;
        }
    }

    public static JoinTypeEnum getByType(Integer joinType){
        for(JoinTypeEnum joinTypeEnum : JoinTypeEnum.values()){
            if (joinTypeEnum.getType().equals(joinType)) {
                return joinTypeEnum;
            }
        }
        return null;
    }
}
